﻿using DotNetExtensions.Core.Jobs;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace DotNetExtensions.Core.Quartz
{
    public class JobResolver : Singleton<JobResolver>
    {
        public static JobInfo Resolve(Type type)
        {
            JobAttribute job = type.GetCustomAttribute<JobAttribute>();
            if (job == null) return null;

            return new JobInfo()
            {
                Cron = string.Join(',', job.Cron),
                Type = type,
                Job = null,
                Disabled = job.Disabled,
                IsSchedule = false,
                JobType = 1
            };
        }
        public static JobInfo Resolve(Type type, object instance)
        {
            JobAttribute job = type.GetCustomAttribute<JobAttribute>();
            return  new JobInfo()
            {
                Cron = string.Join(',', job.Cron),
                Type = type,
                Job = instance,
                Disabled = job.Disabled,
                IsSchedule = false,
                JobType = 1
            };
        }
    }
}
